/*
 * Project: Hell Watch
 * Author: pajoke
 * Copyright: (C) 2014 Hell Prototypes
 * License: GNU GPL v3 (see License.txt)
 * Web: http://www.hellprototypes.com
 */

#ifndef SPI_H_
#define SPI_H_

#include <avr/io.h>
#include "typedefs.h"

#define SET_SCK()		setbit(PORT_SPI_OUT,PIN_SPI_SCK)
#define CLR_SCK()		clrbit(PORT_SPI_OUT,PIN_SPI_SCK)

#define TOGGLE_SCK()	togglebit(PORT_SPI_OUT, PIN_SPI_SCK)

#define SET_MOSI()		setbit(PORT_SPI_OUT,PIN_SPI_MOSI)
#define CLR_MOSI()		clrbit(PORT_SPI_OUT,PIN_SPI_MOSI)

#define GET_MISO()		testbit(PORT_SPI_IN,PIN_SPI_MISO)

#define ROM_Active()	clrbit(PORT_CTRL_OUT,PIN_ROM_CS)
#define ROM_Deactive()	setbit(PORT_CTRL_OUT,PIN_ROM_CS)

void spi_init(void);
void spi_enable(void);
void spi_disable(void);
byte spi_play_one_byte(byte data);
/*
inline byte spi_transfer(byte data)
{
	SPDR = data;
	loop_until_bit_is_set(SPSR, SPIF);
	return SPDR;

}

inline void spi_transfer_nr(byte data)
{
	SPDR = data;
	loop_until_bit_is_set(SPSR, SPIF);

}
*/
#endif /* SPI_H_ */